package me.baicai.weixin.application;



import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


/**
 * @description:
 * @author: [ 超级大白菜 ]
 * @date: 2019-11-08 11:54
 */
@Component
public class Result<E>
{
    private int code;
    private String message;
    private E entity;
    private List<E> list;
    private int total;
    private Map data;


    public Result()
    {
    }

    public Result(int i, List list)
    {
        this.code = i;
        this.list = list;
    }

    public Result(int code, String message)
    {
        this.code= code;
        this.message= message;
    }

    public Result(Result result)
    {
        this.code = result.code;
        this.entity = (E)result.entity;
        this.message = result .message;
        this.list = result.list;
        this.total = result.total;
    }

    public Result(int i, Map map) {
        this.code = i;
        this.data = map;
    }

    public Result(E en) {
        this.entity = en;
        this.code = 200;
    }


    public Result(E en, int code) {
        this.entity = en;
        this.code = code;
    }

    public Result(int i, Map map, E en)
    {
        this.entity = en;
        this.code = i;
        this.data = map;
    }

    public Result<E> error(){
        this.code= 500;
        this.message= "服务器内部错误！";
        return this;
    }

    public Result<E> error(String message){
        this.code= 500;
        this.message=message;
        return this;
    }

    public Result<E> error(Map map, int code){
        this.code= code;
        this.data=map;
        return this;
    }

    public Result<E> error(String message, int code){
        this.code= code;
        this.message=message;
        return this;
    }

    public Result<E> success(){
        this.code= 200;
        this.message="提交成功";
        return this;
    }

    public Result<E> success(String message){
        this.code= 200;
        this.message=message;
        return this;
    }

    public Result<E> success(E entity){
        this.code= 200;
        this.message="提交成功";
        this.entity = entity;
        return this;
    }

    public Result<E> success(List<E> tableData){
        this.code= 200;
        this.message="提交成功";
        this.list = tableData;
        return this;
    }

    public Result<E> success(List<E> tableData, int total){
        this.code= 200;
        this.message="提交成功";
        this.list = tableData;
        this.total = total;
        return this;
    }

    public Map getData() {
        return data;
    }

    public void setData(Map data) {
        this.data = data;
    }

    public int getCode()
    {
        return code;
    }

    public void setCode(int code)
    {
        this.code = code;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public E getEntity()
    {
        return entity;
    }

    public void setEntity(E entity)
    {
        this.entity = entity;
    }

    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    public int getTotal()
    {
        return total;
    }

    public void setTotal(int total)
    {
        this.total = total;
    }
}
